﻿using KaytechSoftware.Cms.App.Areas.Admin.Interfaces;
using KaytechSoftware.Cms.App.Areas.Admin.Models.Base;
using KaytechSoftware.Cms.App.Common;
using KaytechSoftware.Cms.Services.Dto;

namespace KaytechSoftware.Cms.App.Areas.Admin.Models.Entities
{
    public class PageModel : GridEntityModel, IGridEntityModel<PageDto>
    {
        [Id]
        [Label(ResourceKey = "Id")]
        [Renderer(Type = RendererType.Hidden)]
        public long Id { get; set; }

        [Label(ResourceKey = "Title")]
        [Renderer(Type = RendererType.TextBox)]
        public string Title { get; set; }

        [Label(ResourceKey = "Description")]
        [Renderer(Type = RendererType.TextArea)]
        public string Description { get; set; }

        [Label(ResourceKey = "LeftSideRenderer")]
        [Renderer(Type = RendererType.DropDown, UseCollection = CollectionKey.LeftSideRenderer)]
        [SkipInGrid]
        public long? LeftSideRendererId { get; set; }

        [Label(ResourceKey = "RightSideRednerer")]
        [Renderer(Type = RendererType.DropDown, UseCollection = CollectionKey.RightSideRenderer)]
        [SkipInGrid]
        public long? RightSideRednererId { get; set; }

        [Label(ResourceKey = "LeftSideRenderer")]
        [Renderer(Type = RendererType.TextBox)]
        [SkipInDetails]
        public string LeftSideRenderer { get; set; }

        [Label(ResourceKey = "RightSideRednerer")]
        [Renderer(Type = RendererType.TextBox)]
        [SkipInDetails]
        public string RightSideRenderer { get; set; }

        public GridEntityModel FromDto(PageDto dto)
        {
            Id = dto.Id;
            Title = dto.Title;
            Description = dto.Description;
            LeftSideRendererId = dto.LeftSideRendererId;
            RightSideRednererId = dto.RightSideRendererId;
            LeftSideRenderer = dto.LeftSideRendererName;
            RightSideRenderer = dto.RightSideRendererName;
            return this;
        }

        public PageDto ToDto()
        {
            return new PageDto
                {
                    Id = Id,
                    Title = Title,
                    Description = Description,
                    LeftSideRendererId = LeftSideRendererId ?? 0,
                    RightSideRendererId = RightSideRednererId ?? 0,
                    LeftSideRendererName = LeftSideRenderer,
                    RightSideRendererName = RightSideRenderer
                };
        }
    }
}